Skip to content

Add code symbols into outline#972

Open
vezwork wants to merge 5 commits into
mainfrom
feat/code-cell-symbols
Open

Add code symbols into outline#972
vezwork wants to merge 5 commits into
mainfrom
feat/code-cell-symbols

Conversation

@vezwork
Copy link
Copy Markdown
Member

@vezwork vezwork commented May 6, 2026

Addresses an issue mentioned by @juliasilge: #167 (comment)

Screenshot 2026-05-06 at 4 04 39 PM

Adds code symbols under code cells in the outline.

@vezwork vezwork requested a review from juliasilge May 6, 2026 20:06
@posit-snyk-bot
Copy link
Copy Markdown
Contributor

posit-snyk-bot commented May 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 6, 2026

I attempted to add tests until I remembered that our test setup does not have actual LSPs for Python or R in it, so we can't really test this. Well... now that I write that, I realize I could probably mock one out. That seems a little contrived, but maybe still worth it.

@juliasilge
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to be getting two of everything, at least in Positron:

Image

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

I was able to reproduce duplicated language symbols in code cells in Positron with inline outputs enabled. Looking into what is happening.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

@juliasilge In qmds in Positron with Positron › Quarto › Inline Output: Enabled enabled, the following command (from getCodeCellSymbols in this PR) is returning duplicated symbols:

await commands.executeCommand<DocumentSymbol[] | SymbolInformation[]>(
  "vscode.executeDocumentSymbolProvider",
  uri
);

I checked the surrounding context, including the vdoc content. Everything seems to be in order, nothing strange otherwise. When I disabled Positron › Quarto › Inline Output: Enabled and re-open the document, I no longer experience the duplicated symbols issue. It appears to me that the "vscode.executeDocumentSymbolProvider" command does not function as expected when inline outputs are enabled.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 19, 2026

@seeM mocked out fake LSPs in #980. Maybe I can copy that approach for tests in this PR.

@vezwork
Copy link
Copy Markdown
Member Author

vezwork commented May 21, 2026

Cell Diagnostics tests were failing with a message about timing out in CI. The current run of the tests passed, but there wasn't a code change that would've affected the tests or the code tested. The tests seem to be flakey for some reason. Let's keep our eye on that.

Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into the issue with inline output and it is some change we'll need to make over on the Positron side; I'll log that once this is merged.

I do think we need to add at least some basic tests, with a fake in-process symbol provider (not a real LSP). We already do this for the formatting tests. I think the steps would be:

  1. Register a temporary provider in symbols.test.ts with vscode.languages.registerDocumentSymbolProvider({ scheme: "file", pattern: "**/.vdoc.*" }, ...) so it only handles Quarto virtual docs.
  2. Make that provider return each shape in separate tests:
    • DocumentSymbol[]
    • SymbolInformation[]
    • undefined
  3. Run vscode.executeDocumentSymbolProvider on format/basics.qmd or another example file and assert:
    • no throw for undefined
    • code-cell symbols still exist
    • returned embedded symbol names appear under/alongside code-cell outline entries for both result shapes.

That will give us coverage of the middleware logic without having to set up real LSPs.

"vscode.executeDocumentSymbolProvider",
uri
);
if (result.length === 0) return undefined;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result here could also be nothing at all (undefined probably?) so it might be nicer to handle that in this if so it doesn't show up as an error in that catch().

Copy link
Copy Markdown
Member Author

@vezwork vezwork May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know it could be nothing at all? The https://code.visualstudio.com/api/references/commands seems to say that it will always resolve to a list (although it is slightly ambiguous if the type of the list is (SymbolInformation | DocumentSymbol)[] or if its SymbolInformation[] | DocumentSymbol[]). Google search summary says it resolves to SymbolInformation[] | DocumentSymbol[] but with no good citation. Do you know a way to figure out the return type of a command? I attempted to find the definition of the command in the vscode repo, but couldn't.

Comment thread apps/vscode/src/lsp/client.ts Outdated
if (result.length === 0) return undefined;

if (isDocumentSymbol(result[0])) {
return unadjustSymbolRanges(result as DocumentSymbol[], vdoc.language, cellRange.start.line);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to also handle results that come back as SymbolInformation[], as indicated in line 457?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, committed a change for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants